﻿using Blurift.WPFGLControl;
using Crevice2D.Core.Batches;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Patyk.Core;

namespace Crevice2D.WPFEditorHost.Infrastructure
{
    public static class RenderManager
    {
        private static GraphicsDevice _device;
        private static GLGraphicsDevice _graphics;
        private static ContentManager _content;
        private static SpriteBatch _spriteBatch;
        private static PrimitiveBatch _primitveBatch;
        private static SpriteFont _spriteFont;

        public static int ScreenWidth { get; private set; }
        public static int ScreenHeight { get; private set; }

        public static void Initialise(GLGraphicsDevice graphics)
        {
            _graphics = graphics;
            _content = graphics.Content;
        }

        public static void LoadContent(GraphicsDevice graphicsDevice)
        {
            _device = graphicsDevice;
            InitBatches();
        }

        public static void SetViewport(Viewport viewport)
        {
            Device.Viewport = viewport;
            InitBatches();
        }

        private static void InitBatches()
        {
            _spriteBatch = new SpriteBatch(_device);
            _primitveBatch = new PrimitiveBatch(_device);
            _spriteFont = Content.Load<SpriteFont>(ConstantStrings.KootenayFont);
            //_titleSpriteFont = Content.Load<SpriteFont>(@"Fonts/TitleFont");
            //_largeSpriteFont = Content.Load<SpriteFont>(@"Fonts/LargeFont");
        }

        public static Viewport Viewport
        {
            get { return _device.Viewport; }
        }

        public static GraphicsDevice Device
        {
            get { return _device; }
        }

        public static GLGraphicsDevice GLDevice
        {
            get { return _graphics; }
        }

        public static ContentManager Content
        {
            get { return _content; }
        }

        public static SpriteBatch SpriteBatch
        {
            get { return _spriteBatch; }
        }

        public static PrimitiveBatch PrimitiveBatch
        {
            get { return _primitveBatch; }
        }

        public static SpriteFont SpriteFont
        {
            get { return _spriteFont; }
        }

        //public static SpriteFont LargeSpriteFont
        //{
        //    get { return largeSpriteFont; }
        //}

        //public static SpriteFont TitleSpriteFont
        //{
        //    get { return titleSpriteFont; }
        //}

        public static int Width
        {
            get { return _graphics.Width; }
        }

        public static int Height
        {
            get { return _graphics.Height; }
        }
    }
}